package day_02_02_JMM;

import java.util.concurrent.TimeUnit;

/**
 * @Description Java Memory Model：JMM 即java内存模型
 * @Author shihan
 * @Date 2020/11/21 15:18
 * @Version 1.0
 */
public class JMMStudy_01 {

    public static void main(String[] args) {
        MyNumber myNumber = new MyNumber();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + " ********** come in ! ********");
            try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }
            myNumber.add();
            System.out.println(Thread.currentThread().getName() + " : " + myNumber.number);
        },"A").start();

        while (myNumber.number == 10){
            //需要一种通知机制，来告诉 main 线程，共享内存中，MyNumber 对象的数据已经被修改了！
        }

        System.out.println(Thread.currentThread().getName() + "执行结束！");

    }
}

class MyNumber{
    int number = 10;

    public void add(){
        this.number += 10;
    }
}

